package util;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;
import javax.swing.ImageIcon;

public class Util {

	public ImageIcon getImg(String imgName) {
		ClassLoader classLoader = this.getClass().getClassLoader();  
		ImageIcon img = null;

		URL res = classLoader.getResource(imgName); 

		if(res!=null){  
			img = new ImageIcon(res);  
		}else{  
			img = new ImageIcon(imgName);  
		}  

		return img;
	}

	public Sequence getMidi(String midiName) {
		ClassLoader classLoader = this.getClass().getClassLoader();  
		Sequence music = null;

		URL res = classLoader.getResource(midiName); 

		try {
			if(res!=null){  
				music = MidiSystem.getSequence(new File(res.getPath()));  
			}else{  
				music = MidiSystem.getSequence(new File(midiName));
			}  
		} catch (InvalidMidiDataException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  

		return music;
	}
}
